package com.bingo.generate.comm.util;

import com.baomidou.mybatisplus.annotation.TableName;
import com.bingo.generate.comm.entity.ColInfo;
import com.bingo.generate.comm.service.GenerateDbService;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.stream.Collectors;

/**
 * ClassName
 * Description
 * Create by lc
 * Date 2021/12/9 18:41
 */
public class MpTool {
    
    public static void check(Class clazz){
        TableName tableName= (TableName) clazz.getAnnotation(TableName.class);
        String tbName=tableName.value();
        List<Field> fdList= FieldUtils.getAllFieldsList(clazz);
        Map<String, Field> fdMap=new HashMap<>();
        for (Field field : fdList) {
            if(Modifier.isStatic(field.getModifiers())){
                continue;
            }
            fdMap.put(StringHelper.camelToUnderline(field.getName()),field);
        }
        //  转换字段名
        List<ColInfo> list= GenerateDbService.ins.searchCols(tbName);
        //
        Map<String,ColInfo> temp=new HashMap<>();
        for (ColInfo colInfo : list) {
            temp.put(colInfo.getColName(),colInfo);
        }
        //  比较
        for (ColInfo colInfo : list) {
            Field fd = fdMap.get(colInfo.getColName());
            if(fd==null){
                continue;
            }
            fdMap.remove(colInfo.getColName());
            temp.remove(colInfo.getColName());
        }
        System.out.println(" 实体类不存在的字段 "+ temp.keySet());
        System.out.println(" 实体类多余的字段 "+fdMap.keySet());

    }
    
}
